package com.iwish.server.model;

import org.apache.log4j.Logger;
import org.apache.mina.core.session.IoSession;

import com.iwish.server.storage.model.Obj;
import com.iwish.server.util.DateUtil;

public class UpdateService extends ServiceTemplate{
	
	Logger logger = Logger.getLogger(UpdateService.class);

	private double x;
	private double y;
	private double z;
	private String uid;
	private int page_num;
	private String filter_type;
	private String custom_filter;
	
	public UpdateService()
	{
		
	}
	
	public UpdateService(
			double x, 
			double y, 
			double z,
			String uid, 
			int page_num, 
			String filter_type,
			String custom_filter)
	{
		this.x = x;
		this.y = y;
		this.z = z;
		
		this.uid = uid;
		
		this.page_num = page_num;
		
		this.filter_type = filter_type;
		
		this.custom_filter = custom_filter; // now is empty
		
	}
	
	public boolean update(IoSession session)
	{
		System.out.println(x + ";"
				+ y + ";"
				+ z + ";"
				+ uid + ";"
				+ page_num + ";"
				+ filter_type + ";"
				+ custom_filter + ";");
		
		//set user location to database
		//TODO: 其实应该把set location的操作放到find near后面
		Obj.User.Builder user = (Obj.User.Builder) get(uid, Obj.User.class, 30);
		
		Obj.Location.Builder loc = Obj.Location.newBuilder();
		loc.setX(x);
		loc.setY(y);
		loc.setZ(z);
		loc.setUpdateDate(DateUtil.getFullDate());
		user.setLocation(loc);
		
		set(Obj.User.class, uid,user);
		
		//find near user info
		
		return true;
	}

	public double getX() {
		return x;
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}

	public double getZ() {
		return z;
	}

	public void setZ(double z) {
		this.z = z;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public int getPage_num() {
		return page_num;
	}

	public void setPage_num(int page_num) {
		this.page_num = page_num;
	}

	public String getFilter_type() {
		return filter_type;
	}

	public void setFilter_type(String filter_type) {
		this.filter_type = filter_type;
	}

	public String getCustom_filter() {
		return custom_filter;
	}

	public void setCustom_filter(String custom_filter) {
		this.custom_filter = custom_filter;
	}
	
	
}
